package com.a214.yxz.yuejian013.Fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.a214.yxz.yuejian013.Base.BaseSFragment;
import com.a214.yxz.yuejian013.JavaBean.ClubBean;
import com.a214.yxz.yuejian013.JavaBean.MasterBean;
import com.a214.yxz.yuejian013.Adapter.ClubMasterAdapter;
import com.a214.yxz.yuejian013.Listener.ServiceListener;
import com.a214.yxz.yuejian013.Model.ResModel;
import com.a214.yxz.yuejian013.R;

import java.util.List;

/**
 * A simple {@link BaseSFragment} subclass.
 */
public class ClubInfoFragment extends BaseSFragment {

    private ServiceListener<ClubBean> info_listener;
    private ServiceListener<List<MasterBean>> master_listener;
    private ResModel model = new ResModel("gson",getSessionID());
    private TextView intro,address,phone,openTime;
    private RecyclerView coach_list;
    private ClubMasterAdapter adapter;
    private RecyclerView.LayoutManager layoutManager;



    public ClubInfoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_club_info, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        intro= (TextView) view.findViewById(R.id.club_info_intro);
        address= (TextView) view.findViewById(R.id.club_info_address);
        phone= (TextView) view.findViewById(R.id.club_info_phone);
        openTime= (TextView) view.findViewById(R.id.club_info_openTime);



        coach_list= (RecyclerView) view.findViewById(R.id.club_info_coach_list);

        layoutManager = new LinearLayoutManager(getContext());
        adapter=new ClubMasterAdapter(getContext());
        coach_list.setLayoutManager(layoutManager);
        coach_list.setAdapter(adapter);


        info_listener=new ServiceListener<ClubBean>() {
            @Override
            public void onResponse(ClubBean l) {
                intro.setText(l.getIntroduction().toString());
                address.setText(l.getClub_contact().toString());
                phone.setText(l.getClub_tel().toString());
                openTime.setText(l.getOpen_time().toString());
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
            }
        };

        master_listener=new ServiceListener<List<MasterBean>>() {
            @Override
            public void onResponse(List<MasterBean> l) {
                adapter.setList(l);
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
            }
        };

        model.getOne("club",getActivity().getIntent().getStringExtra("club_id"),info_listener);
        //model.getClubDetail("master",getActivity().getIntent().getStringExtra("club_id"),master_listener);
        model.getClubDetail("master","0",master_listener);
    }
}
